import { createApp } from 'vue'
import './style.less'
import './utils/flexible.js'
import App from './App.vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import store from '@/store'
import router from './router'
import loginHttp from "@/https/login.js"
import menuHttp from "@/https/menu.js";
import { ElMessage } from 'element-plus'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
// v3-drag-zoom 组件
import V3DragZoom from "v3-drag-zoom";
import { getMenuRoutes } from "@/utils/menuAuth.js";
// v3-drag-zoom 全局样式（必须导入，否则无法正常使用）
import "v3-drag-zoom/dist/style.css";
import Storage from "@/utils/storage.js"; // storage工具类，简单的封装
const app = createApp(App)
app.use(ElementPlus, {
    locale: zhCn,
})
app.use(V3DragZoom)
router.beforeEach((to, from, next) => {
    console.log(to, from)
    if (to.path === '/login') {
        console.log('1111')
        next()
    } else {
        if(to.fullPath.indexOf('app') > -1) {
            next()
        } else {
            if(Storage.localGet("tokenValue")) {
                console.log(to.matched.length, 'length')
                if(to.matched.length == 0) {
                    console.log('444')
                    getMenuRoutes(() => next({ ...to, replace: true }));
                } else {
                    console.log('2222')
                    next()
                }
            } else {
                console.log('3333')
                next({path: '/login', replace: true})
            }
        }
    } 
})
app.use(store)
app.use(router)
app.mount('#app')